// shengchanLocal.js 生产任务本地存储操作工具，包含生产任务的增删查改等方法
const STORAGE_KEY = 'shengchanjihua';

export function getShengchanList() {
  return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
}

export function saveShengchanList(list) {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

export function addShengchan(item) {
  const list = getShengchanList();
  item.id = Date.now();
  list.push(item);
  saveShengchanList(list);
}

export function updateShengchan(item) {
  const list = getShengchanList();
  const idx = list.findIndex(i => i.id === item.id);
  if (idx !== -1) {
    list[idx] = item;
    saveShengchanList(list);
  }
}

export function deleteShengchan(ids) {
  let list = getShengchanList();
  list = list.filter(i => !ids.includes(i.id));
  saveShengchanList(list);
} 